<template>
  <div class="pc">
    <el-carousel :interval="4000" height="370px">
      <el-carousel-item v-for="item in 6" :key="item">
        <img
          src="http://ehall.dgut.edu.cn/static/banner6.a5cff40e.jpg"
          alt=""
          srcset=""
        />
      </el-carousel-item>
    </el-carousel>
    <el-tabs v-model="activeName" type="border-card">
      <el-tab-pane label="所有问卷" name="1">
        <el-card shadow="never" :body-style="{ padding: '20px' }">
          <div
            style="display: flex; justify-content: space-between"
            slot="header"
          >
            <div>
              <span style="font-size: 20px">所有问卷</span>
              <span style="font-size: 12px; color: #979797; margin-left: 15px"
                >All Questionnaires</span
              >
            </div>

            <van-search
              style="padding: 0; width: 400px"
              v-model="listQuery.name"
              show-action
              shape="round"
              placeholder="请输入搜索关键词"
            >
              <template #action>
                <div @click="getSurvey">搜索</div>
              </template>
            </van-search>
          </div>
          <div class="container">
            <div
              @click="show(i)"
              class="item"
              :style="{
                'min-width': b + 'px',
                'max-width': b + 'px',
              }"
              v-for="i in list"
              :key="i.id"
            >
              <el-tooltip
                class="item"
                effect="dark"
                :content="i.title"
                placement="top"
                :enterable="false"
              >
                <div class="box">
                  <div class="item-top">
                    <div class="left">
                      <svg style="height: 60px; width: 60px" aria-hidden="true">
                        <use
                          :xlink:href="'#' + JSON.parse(i.setting).icon"
                        ></use>
                      </svg>
                    </div>
                    <div class="right">
                      <h4 class="title" :style="{ width: b - 90 + 'px' }">
                        {{ i.title }}
                      </h4>
                      <div style="font-size: 12px; color: #979797">
                        {{ new Date(i.create_time).toLocaleString() }}
                      </div>
                      <el-rate :value="5" disabled></el-rate>
                    </div>
                  </div>
                  <div class="item-bottom">
                    <span>SURVEY-00{{ i.id }}</span>
                    <span>{{ i.submit_count }}人填写</span>
                  </div>
                </div>
              </el-tooltip>
            </div>
          </div>
        </el-card></el-tab-pane
      >
      <el-tab-pane label="已填写" name="2">
        <el-table :data="data" border stripe>
          <el-table-column
            label="名称"
            align="center"
            prop="survey"
          ></el-table-column>
          <el-table-column label="填写时间" align="center" prop="create_time">
            <template slot-scope="{ row }">
              <span>{{ new Date(row.create_time).toLocaleString() }}</span>
            </template>
          </el-table-column>
          <el-table-column label="审核状态" align="center">
            <template slot-scope="{ row }">
              <el-tag
                type="info"
                size="mini"
                effect="dark"
                v-if="row.status == '未审核'"
                >{{ row.status }}</el-tag
              >
              <el-tag
                type="success"
                size="mini"
                effect="dark"
                v-if="row.status == '审核通过'"
                >{{ row.status }}</el-tag
              >
              <el-tag
                type="danger"
                size="mini"
                effect="dark"
                v-if="row.status == '审核不通过'"
                >{{ row.status }}</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" prop="">
            <template slot-scope="{ row }">
              <el-button
                type="warning"
                size="small"
                v-if="row.status == '审核不通过'"
                @click="SurveyUpdate(row.id)"
                >修改</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <el-dialog
      :visible.sync="dialogshow"
      width="70%"
      @close="dialogshow = false"
    >
      <div slot="title" class="el-title">
        <div style="display: flex; align-items: center">
          <svg style="height: 60px; width: 60px" aria-hidden="true">
            <use :xlink:href="'#' + setting.icon"></use>
          </svg>
          <span>{{ title }}</span>
        </div>
        <el-divider direction="horizontal" content-position="left"></el-divider>
      </div>
      <div class="setting">
        <div style="white-space: nowrap">流程说明：</div>
        <span v-html="setting.process"> </span>
      </div>
      <div class="setting">
        <div style="white-space: nowrap">业务说明：</div>
        <span v-html="setting.business"></span>
      </div>
      <span class="el-footer" slot="footer">
        <el-divider direction="horizontal" content-position="left"></el-divider>
        <el-button v-if="is_active" type="primary" size="mini" @click="survey()"
          >办理</el-button
        >
        <span v-else style="font-size: 12px; color: red">功能测试中。。。</span>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getSurvey, getSubmitSurvey, SurveyUpdate } from "@/api/work";
export default {
  data() {
    return {
      activeName: "1",
      b: "257",
      list: [],
      title: null,
      is_active: false,
      setting: {},
      dialogshow: false,
      id: null,
      listQuery: {
        name: null,
      },
      listQuery1: {
        page: 1,
        limit: 10,
      },
      data: [],
    };
  },
  created() {
    this.getSurvey();
    this.getSubmitSurvey();
  },
  mounted() {
    this.withChange();
    window.onresize = () => {
      this.withChange();
    };
  },
  methods: {
    withChange() {
      let clientWidth =
        document.getElementsByClassName("container")[0].clientWidth;
      if (parseInt(clientWidth / 246.5) > 1) {
        this.b = clientWidth / parseInt(clientWidth / 246.5) - 1.5;
      } else {
        this.b = clientWidth;
      }
    },
    getSurvey() {
      getSurvey(this.listQuery).then((res) => {
        this.list = res;
      });
    },
    getSubmitSurvey() {
      getSubmitSurvey(this.listQuery1).then((res) => {
        this.data = res.results;
      });
    },
    survey() {
      this.$router.push({ name: "Survey", query: { id: this.id } });
      this.dialogshow = false;
    },
    show(i) {
      this.id = i.id;
      this.title = i.title;
      this.setting = JSON.parse(i.setting);
      this.is_active = i.is_active;
      this.dialogshow = true;
    },
    SurveyUpdate(id) {
      this.$router.push({name:'WorkUpdate',query:{id:id}})
    },
  },
};
</script>

<style scoped>
.pc {
  padding-bottom: 20px;
}
.setting {
  display: flex;
  margin: 10px 0;
}
.top-panel {
  position: absolute;
  top: 20px;
  left: 50%;
  width: 50vw;
  height: 80px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.2);
  transform: translate(-50%, 0);
  z-index: 10;
  display: flex;
}
.top-panel-left {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  padding: 0 20px;
}
.top-panel-right {
  padding: 10px;
}
.top-panel-right-top {
  display: flex;
}
.el-tabs {
  margin: 1.5% 10%;
}
.container {
  display: flex;
  flex-wrap: wrap;
  /* justify-content: center; */
}
.item-top {
  display: flex;
  margin-bottom: 6px;
}
.item {
  min-width: 25%;
  height: 115.4px;
  box-sizing: border-box;
  padding: 5px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  flex-direction: column;
}
.box {
  transition: all 0.2s ease-out;
  border-radius: 6px;
  padding: 10px;
}
.item:hover .box {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
  transform: scale(1.05);
}
.left img {
  width: 50px;
  height: 50px;
}
.right >>> .el-rate__icon {
  font-size: 12px;
}
.right {
  padding-left: 10px;
}
.right > * {
  margin-bottom: 6px;
}
.item-bottom {
  border-top: 1px solid #ccc;
  padding-top: 6px;
  display: flex;
  justify-content: space-between;
  color: #979797;
  font-size: 12px;
}
.title {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.pc >>> .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}

.pc >>> .el-dialog .el-dialog__body {
  flex: 1;
  overflow: auto;
  padding: 10px 20px;
  display: flex;
  min-height: 100px;
  flex-direction: column;
  justify-content: space-around;
}
.el-title >>> .el-divider {
  margin: 10px 0;
}

.el-footer >>> .el-divider {
  margin: 10px 0;
}
.pc >>> .el-dialog__footer {
  padding: 0px 20px 10px;
}
</style>
